package com.cjl.help;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class MyScheduledExecutorService3 {
    public static void main(String[] args) {
        final int[] i = {0};
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("start Run Scheduler  1：" + new Date());
                int num = 2/0;
                System.out.println("end Run Scheduler 1：" + new Date());
            }
        },1,3, TimeUnit.SECONDS);

        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("start Run Scheduler  2：" + new Date());
                i[0]++;

                if (i[0] == 5){
                    executorService.shutdown();
                }
            }
        },1,3, TimeUnit.SECONDS);



    }
}
